package com.example.projectcode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.projectcode.mapper.TestCstuanMapper;
import com.example.projectcode.model.Choice;
import com.example.projectcode.model.TestCstuan;
import com.example.projectcode.service.ChoiceService;
import com.example.projectcode.service.TestCstuanService;
import com.example.projectcode.vo.TestCstuanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TestCstuanServiceImpl extends ServiceImpl<TestCstuanMapper,TestCstuan> implements TestCstuanService {

    @Autowired
    private ChoiceService choiceService;

    @Autowired
    private TestCstuanMapper testCstuanMapper;

    @Override
    public int insertChoice(TestCstuanVo testCstuanVo) {

        TestCstuan testCstuan = new TestCstuan();
       Choice choice = choiceService.selectChoiceByCId(testCstuanVo.getChoiceId());
       if (testCstuanVo.getTestCstuanc().equals(choice.getCAnswer())){
           testCstuan.setTestCFeedback("true");
       }else {
           testCstuan.setTestCFeedback("flase");
       }

       testCstuan.setTestCStuanc(testCstuanVo.getTestCstuanc());
       testCstuan.setStuId(testCstuanVo.getStuId());
       testCstuan.setTestCid(testCstuanVo.getTestCid());


        return baseMapper.insert(testCstuan);
    }

    @Override
    public List<TestCstuan> selectAllByStuId(Integer stuId) {
        return baseMapper.selectList(new QueryWrapper<TestCstuan>().eq("Stu_id",stuId));
    }

    @Override
    public int updatetestcstuanById(Integer testCstuanid, String cfeedback) {
        return testCstuanMapper.updatetestcstuan(testCstuanid,cfeedback);
    }
}
